package com.ssm.juc.lock;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch
 * 例子：5 个运动员同时准备，然后等待发令枪一起启动
 */
public class CountDownLatchTest1 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                //准备完毕......运动员都阻塞在这，等待号令
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                String parter = "【" + Thread.currentThread().getName() + "】";
                System.out.println(parter + "开始执行......");
            }).start();
        }
        Thread.sleep(2000);// 裁判准备发令
        countDownLatch.countDown();// 发令枪:执行发令
    }

}